<?php

namespace App\Http\Requests\Admin;

use App\Http\Requests\Request;
use App\Models\NormalReply;

class SubscribeReplyStore extends Request
{
    public function rules()
    {
        return [
            'type' => [
                'required',
                function($attribute, $value, $fail) {
                    if (!in_array($value, array_keys(NormalReply::$replyMsgTypesMap))) {
                        return $fail('回复消息类型错误');
                    }
                }
            ],
            'material_id' => [
                function($attribute, $value, $fail) {
                    $type = $this->request->get('type');
                    if (
                        ($type == NormalReply::REPLY_IMAGE || $type == NormalReply::REPLY_NEWS)
                        && !$value
                    ) {
                        return $fail('素材id不能为空');
                    }
                }
            ]
        ];
    }
}
